package com.example.qsindusty.jmm_spline.api;








import com.example.qsindusty.jmm_spline.Config.Config;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * Created by Administration on 2018/3/5.
 */

public class ApiManager {
   JMMApi jmmApi ;
    private static OkHttpClient.Builder mClient;
    private static ApiManager apiManager ;
   static   HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();


    public ApiManager( ) {

    }
    public  static  ApiManager getInstence(){
        if (apiManager==null){
            synchronized (ApiManager.class){
                if (apiManager==null){
                    apiManager= new ApiManager();
                }
            }
        }
       httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        mClient = new OkHttpClient.Builder();
        mClient.addInterceptor(httpLoggingInterceptor);
        mClient.readTimeout(10, TimeUnit.SECONDS);
        mClient.connectTimeout(9, TimeUnit.SECONDS);
        return apiManager;
    }
      public  JMMApi getJmmApi(){
          Retrofit retrofit = new Retrofit.Builder()
                  .client(mClient.build())
                  .baseUrl(Config.URL_JMMURL)
                  .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                  .addConverterFactory(GsonConverterFactory.create()).build();
          return  retrofit.create(JMMApi.class) ;
      }



}
